﻿using System;
using System.Linq;
using Myotragus.Data.Util;

namespace Myotragus.Data.Emit
{
	public class AutoPropertiesEntityGenerator : EntityGenerator, IAutoProperties
	{
		public AutoPropertiesEntityGenerator(IDynamicAssembly dynamicAssembly, INameGenerator nameGenerator)
			: base(dynamicAssembly, nameGenerator)
		{
		}

		protected override void AttachImplementation(IDynamicType type, Type interfaceType)
		{
			foreach (var prop in ReflectionHelper.GetProperties(interfaceType)
							.Where(p => p.CanRead && p.CanWrite))
				type.DefineAutomaticProperty(prop.Name, prop.PropertyType);
		}
	}
}